<template>
	<view class="content col">
		<view class="row_wrap1 row">
			{{hospital}}
		</view>
		<view class="row_wrap2 row_between">
			<view class="row-item">
				{{name}}
			</view>
			<view class="row-item">
				{{department}}
			</view>
			<view class="row-item">
				{{title}}
			</view>
		</view>
		<view class="row_wrap3">
			<image :src="qrImage" mode="aspectFill"></image>
		</view>
		<view class="row_wrap4">
			扫描上方二维码，向医生一对一咨询
		</view>
		<view class="row_wrap5">
			1 出示二维码让患者扫码<br>
			2 扫码后关注问诊公众号即可建立医患关系<br>
			3 患者在微信公众号“我的医生”中可找到医生进行咨询
		</view>

		<!-- 底部分享弹窗 -->
		<uni-share :shareShow="shareShow" :contents="contents"
		@cancelshow="this.shareShow=false"></uni-share>
	</view>
</template>

<script>
	import { BASE_URL, qrcode ,shareToConsumer} from '@/utils/api';
	import uniShare from "@/components/uni-share.vue"
	export default {
		components: {
			uniShare
		},
		data() {
			return {
				type: '',
				shareText: 'uni-app可以同时发布成原生App、小程序、H5，邀请你一起体验！',
				href:"https://uniapp.dcloud.io",
				image: 'http://gzf.liangyicloud.xyz/h5/images/logo_icon.png',
				shareType:0,
				shareShow:false,
				id: '',
				qrImage: '',
				name: '',
				hospital: '复旦大学附属上海市第五人民医院',
				department: '小儿内科',
				title: '副主任',
				contents:{ //详情内容
					thumb:'',
					title1: '',
					desc: '',
					href: ''
				},
			};
		},
		onLoad(opt) {
			this.id = opt.id;
			this.qrcode();
			this.shareToConsumer();
			if(uni.getStorageSync("userInfo").name){
				this.name = uni.getStorageSync("userInfo").name;
			}
			if(uni.getStorageSync("userInfo").title){
				this.title = uni.getStorageSync("userInfo").title;
			}
			if(uni.getStorageSync("userInfo").hospital){
				this.hospital = uni.getStorageSync("userInfo").hospital;
			}
			if(uni.getStorageSync("userInfo").department){
				this.department = uni.getStorageSync("userInfo").department;
			}
			
		},
		methods: {
			async qrcode(){
				uni.showLoading();
				let res = await qrcode(this.id);
				if(res.status == 0){
					let base64Data = res.data;
					this.qrImage = base64Data;
					uni.hideLoading();
					//console.log(this.qrImage);
				}
			},
			togglePopup(type, o) {
				this.type = type;
				this.$refs[o].open();
			},
			cancel(type) {
				this.$refs[type].close();
			},
			compress(){//压缩图片 图文分享要求分享图片大小不能超过20Kb
				console.log('开始压缩');
				let img = this.image;
				return new Promise((res) => {
					var localPath = plus.io.convertAbsoluteFileSystem(img.replace('file://', ''));
					console.log('after' + localPath);
					// 压缩size
					plus.io.resolveLocalFileSystemURL(localPath, (entry) => {
						entry.file((file) => {// 可通过entry对象操作图片 
							console.log('getFile:' + JSON.stringify(file));
							if(file.size > 20480) {// 压缩后size 大于20Kb
								plus.zip.compressImage({
									src: img,
									dst: img.replace('.jpg', '2222.jpg').replace('.JPG', '2222.JPG'),
									width: '10%',
									height: '10%',
									quality: 1,
									overwrite: true
								}, (event) => {
									console.log('success zip****' + event.size);
									let newImg = img.replace('.jpg', '2222.jpg').replace('.JPG', '2222.JPG');
									res(newImg);
								}, function(error) {
									uni.showModal({
										content:'分享图片太大,需要请重新选择图片!',
										showCancel:false
									})
								});
							}
						});
					}, (e) => {
						console.log('Resolve file URL failed: ' + e.message);
						uni.showModal({
							content:'分享图片太大,需要请重新选择图片!',
							showCancel:false
						})
					});
				})
			},
			change(e) {
				console.log(e.show)
			},
			async shareToConsumer(){
				let res = await shareToConsumer();
				console.log(res)
				if(res.status==0){
					this.contents.title1=res.data.title;
					this.contents.desc=res.data.desc;
					this.contents.thumb=res.data.thumb;
					this.contents.href=res.data.redirect;
				}
			}
		},
		onNavigationBarButtonTap(e){
			console.log(e)
			if(e.key=='share'){
				this.shareShow = true
			}
			console.log(this.shareShow)
		}
	}
</script>

<style lang="scss">
	page {
		background: #F4F4F4;
	}

	.content {
		margin: 100upx 65upx 191upx 65upx;
		background: #FFFFFF;
		height: 915upx;

		.row_wrap1 {
			height: 32upx;
			color: rgba(173, 133, 252, 1);
			font-size: 34upx;
			margin-top: 101upx;
		}

		.row_wrap2 {
			height: 32upx;
			width: 382upx;
			font-size: 34upx;
			margin-top: 39upx;

			.row-item {
				line-height: 1.0;
			}
		}

		.row_wrap3 image {
			width: 339upx;
			height: 339upx;
			margin-top: 39upx;
		}

		.row_wrap4 {
			line-height: 1.0;
			margin-top: 42upx;
			color: rgba(153, 153, 153, 1);
			font-size: 24upx
		}

		.row_wrap5 {
			line-height: 1.5;
			margin-top: 39upx;
			color: rgba(153, 153, 153, 1);
			font-size: 24upx;
			width: 450upx;
		}
	}

	/* 底部分享 */
	.uni-share {
		background: #fff;
	}

	.uni-share-title {
		line-height: 60upx;
		font-size: 24upx;
		padding: 15upx 0;
		text-align: center;
	}

	.uni-share-content {
		display: flex;
		flex-wrap: wrap;
		padding: 15px;
	}

	.uni-share-content-box {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 25%;
		box-sizing: border-box;
	}

	.uni-share-content-image {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 60upx;
		height: 60upx;
		overflow: hidden;
		border-radius: 10upx;
	}

	.uni-share-content-image .image {
		width: 100%;
		height: 100%;
	}

	.uni-share-content-text {
		font-size: 26upx;
		color: #333;
		padding-top: 5px;
		padding-bottom: 10px;
	}

	.uni-share-btn {
		height: 90upx;
		line-height: 90upx;
		border-top: 1px #f5f5f5 solid;
		text-align: center;
		color: #666;
	}
</style>
